import static org.junit.Assert.*;

import java.net.Socket;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


public class CroupierTest
{
	private static Player playersWithTheSameBets[];
	private static Player playersWithDifferentBets[];
	private static Game game;
	private static Deck deck;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
		game = new Game(6, 100, 4444, "pierwszy", 10, 5);
		deck = new Deck();
		for(int i=1; i<=6; i++){
			playersWithTheSameBets[i]= new Player(i, new Socket("localhost",4444), 100, game, deck);
			playersWithDifferentBets[i]= new Player(i, new Socket("localhost",4454), 100, game, deck);
		
		}
		playersWithTheSameBets = new Player[7];
		playersWithTheSameBets[1].setBet(30);
		playersWithTheSameBets[1].setStatus(Player.PLAYER_OUT_OF_GAME);
		playersWithTheSameBets[2].setBet(10);
		playersWithTheSameBets[2].setStatus(Player.PLAYER_OUT_OF_GAME);
		playersWithTheSameBets[3].setBet(20);
		playersWithTheSameBets[3].setStatus(Player.PLAYER_PLAYED_ALLIN);
		playersWithTheSameBets[4].setBet(30);
		playersWithTheSameBets[4].setStatus(Player.PLAYER_IN_GAME);
		playersWithTheSameBets[5].setBet(30);
		playersWithTheSameBets[5].setStatus(Player.PLAYER_IN_GAME);
		playersWithTheSameBets[6].setBet(30);
		playersWithTheSameBets[6].setStatus(Player.PLAYER_PLAYED_ALLIN);
		
		playersWithDifferentBets = new Player[6];
		playersWithDifferentBets[1].setBet(30);
		playersWithDifferentBets[1].setStatus(Player.PLAYER_OUT_OF_GAME);
		playersWithDifferentBets[2].setBet(30);
		playersWithDifferentBets[2].setStatus(Player.PLAYER_OUT_OF_GAME);
		playersWithDifferentBets[3].setBet(20);
		playersWithDifferentBets[3].setStatus(Player.PLAYER_PLAYED_ALLIN);
		playersWithDifferentBets[4].setBet(30);
		playersWithDifferentBets[4].setStatus(Player.PLAYER_IN_GAME);
		playersWithDifferentBets[5].setBet(40);
		playersWithDifferentBets[5].setStatus(Player.PLAYER_IN_GAME);
		playersWithDifferentBets[6].setBet(20);
		playersWithDifferentBets[6].setStatus(Player.PLAYER_PLAYED_ALLIN);
		
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
	}

	@Before
	public void setUp() throws Exception
	{		
	}

	@After
	public void tearDown() throws Exception
	{
	}

	@Test
	public void whichPlayerNextTest()
	{
		for(int i=2;i<=6; i++){
			assertEquals(1, Croupier.whichPlayerNext(i, i));
		}
	}
	@Test
	public void drawDealerTest(){
		for (int i=2; i<=6; i++){
			for(int j=0; j<100; j++){
				int whoDealer = Croupier.drawDealer(i);
				assertTrue(1<=whoDealer && whoDealer<=i);
			}
		}
	}
	@Test
	public void possibleMovesTest(){
		//pierwsza runda i brak kasy by przebić
		assertEquals("CF", Croupier.possibleMoves(10, 10,false,20, 1));
		assertEquals("CRF",Croupier.possibleMoves(20,30 ,false, 30, 1));
		assertEquals("FA",Croupier.possibleMoves(20,5 ,false, 30, 1));
		assertEquals("RF",Croupier.possibleMoves(30,5 ,false, 30, 1));
		assertEquals("FA",Croupier.possibleMoves(30,0 ,false, 30, 1));
		//kolejne rundy
		assertEquals("HBF", Croupier.possibleMoves(20, 10,false,20, 2));
		assertEquals("HF",Croupier.possibleMoves(20,0 ,false, 20, 2));
		assertEquals("CF",Croupier.possibleMoves(20,10 ,true, 30, 2));
		assertEquals("FA",Croupier.possibleMoves(20,5 ,true, 30, 2));
		assertEquals("RF",Croupier.possibleMoves(30,5 ,true, 30, 2));
		assertEquals("FA",Croupier.possibleMoves(30,0 ,true, 30, 2));
	}
	@Test
	public void havePlayersTheSameBetsTest(){
		assertTrue(Croupier.havePlayersTheSameBets(playersWithTheSameBets));
		assertFalse(Croupier.havePlayersTheSameBets(playersWithDifferentBets));
	}

}
